package com.itheima.edu.info.manger.dao;
import com.itheima.edu.info.manger.domain.Student;

import java.util.ArrayList;

public class OtherStudentDao implements BaseStudentDao{
    // 创建学生对象数组
    private static ArrayList<Student> students=new ArrayList<>();
    static {
        Student stu1=new Student("heima001","张三","23","1999-11-11");
        Student stu2=new Student("heima002","李四","24","1998-11-11");
       students.add(stu1);
       students.add(stu2);
    }
    // 查看学生方法
    public  Student[] findAllStudent() {
        Student[] stu=new Student[students.size()];
        for (int i = 0; i < stu.length; i++) {
            stu[i]=students.get(i);
        }
        return stu;
    }
//删除学生
    public  void deleteStudentById(String did) {
        int index=getIndex(did);
        students.remove(index);
    }
//修改学生
    public  void updateStudentById(String uid,Student newStu) {
        int index = getIndex(uid);
        students.set(index,newStu);

    }
    // 添加学生方法
    public  boolean addStudent(Student stu) {
      students.add(stu);
            return true;
    }
    //获取索引
    public  int getIndex(String id){
        int index=-1;
        for (int i = 0; i < students.size(); i++) {
            Student stu= students.get(i);
            if (stu!=null&&stu.getId().equals(id)){
                index=i;
                break;
            }
        }
        return index;
    }
}
